﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InvariantWM.NormalizerUtils
{
    public class Point2D
    {
        double m_x;
        double m_y;
        public Point2D(double x, double y)
        {
            this.m_x = x;
            this.m_y = y;
        }
        public double getX()
        {
            return m_x;
        }
        public double getY()
        {
            return m_y;
        }
        public static double point2dDistance(double x1, double y1, double x2, double y2)
        {
            return Math.Sqrt(Math.Pow(x1 - x2, 2) + Math.Pow(y1 - y2, 2));
        }
        public static Point2D Point2DRotate(Point2D p, double angle, Point2D center){
            double originalx = p.getX();
            double originaly = p.getY();
            double cos = Math.Cos(-angle);
            double sin = Math.Sin(-angle);


            Point2D paux1 = new Point2D(originalx, originaly);

            Transform2D moveToOrigin = new Transform2D(1, 0, 0, 1, -center.getX(), -center.getY());
            Point2D paux2 = moveToOrigin.Transform(paux1);

            Transform2D reverse2DRotation = new Transform2D(cos, -sin, sin, cos, 0, 0);
            Point2D paux3 = reverse2DRotation.Transform(paux2);

            Transform2D backFromOrigin = new Transform2D(1, 0, 0, 1, center.getX(), center.getY());
            Point2D paux4 = backFromOrigin.Transform(paux3);
            //ahora ya tengo en originalx, originaly las coordenadas trasnformadas del punto en la primera
            //imagen, lo que puedo hacer ahora es interpolar el valor de dicho punto respecto a los que
            //están alrededor...
            return paux4;
        }
        public static Point2D detranslate(Point2D p, Point2D offset) {
            Transform2D t = new Transform2D(1, 0, 0, 1, - offset.getX(), - offset.getY());
            return t.Transform(p);
        }

    }

}
